<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <link href="assets/jQuery-File-Upload-9.12.3/css/jquery.fileupload.css" rel="stylesheet"/>
    <link href="assets/jQuery-File-Upload-9.12.3/css/jquery.fileupload-ui.css" rel="stylesheet"/>
    <link href="assets/DataTables-1.10.11/media/css/dataTables.bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/images/log.ico" rel="shortcut icon">
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <style type="text/css">
        .mapBall{
            width:20px;
            height:20px;
            background: red;
            border-radius: 50%;
            position: absolute;
        }
        .table>tbody>tr>td{
            text-align:center;
            line-height: 15px;
            font-size: 15px;
        }
        .table>thead:first-child>tr:first-child>th{
            text-align:center;
        }
    </style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <!--顶部导航栏开始-->
    <header id="top_header" class="main-header">
        <!-- Logo -->
        <a href="main_page.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>T</b>pson</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!--<img src="assets/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i>
                        <span>主页</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview active">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-yellow"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-red"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                <b>数据导入导出</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#"><i class="fa fa-chain-broken"></i> 监测点配置</a> </li>
                <li><a href="monitor_config_export.html"><i class="fa fa-circle-o"></i> 数据导入导出</a></li>
            </ol>
        </section>
        <section class="invoice">
        <div class="row">
               <div class="box box-info" style="margin-bottom: 0px">
                   <div class="box-header">
                       <h4 class="box-title"><b>导入导出数据</b></h4>
                   </div>
                   <div class="box-body">
                       <div class="row">
                               <div class="col-sm-10">
                                   <div class="col-sm-2" ><input id="photoCover" class="input-large" type="text" disabled></div>
                                   <div class="col-sm-2" >
                                        <form id="fileForm" action="" method="post" enctype="multipart/form-data"   target="frameFile" >
                                                <span class="btn btn-info fa fa-folder-open   fileinput-button">
                                                    <!--<i class="glyphicon glyphicon-plus"></i>-->
                                                    <span>打开xlsx</span>
                                                    <input id="map_file" type="file" multiple  name="file" accept=".xls">
                                                </span>
                                            <input id="submit" name="submit" type="submit" style="display: none">
                                        </form>
                                        <iframe id="frameFile" name="frameFile" style="display: none;"></iframe>
                                   </div>
                                   <div class="col-sm-2"style="margin: 0" >
                                       <button id="rest" type="button" class="btn btn-warning fa fa-upload"  > 重置</button>
                                   </div>
                                   <div class="col-sm-2">
                                       <button id="upload" type="button" class="btn btn-success fa fa-upload"  >提交xlsx</button>
                                   </div>
                                   <div class="col-sm-2">
                                       <button id="exportAllXlsx" type="button" class="btn btn-warning btn-block fa fa-edit" >下载录入模板</button>
                                   </div>
                               </div>
                       </div>
                   </div>
               </div>
        </div>
            <div class="row">
                    <div class="box box-warning" style="margin-bottom: 0px">
                        <div class="box-header">
                            <h4 class="box-title"><b>未配置地图信息的监测点列表</b></h4>
                        </div>
                        <div class="box-body">
                            <table id="monitor_no_map_table" class="table table-bordered table-striped" style="width: 100%">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>监测点名称</th>
                                    <th>所属用户信息传输装置</th>
                                    <th>地理位置信息</th>
                                    <th>传感器类型</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="monitor_no_map_body">

                                </tbody>
                            </table>
                        </div>
                    </div>
            </div>
            <div class="row">
                <div class="col-sm-12" id="config_monitor_map" style="padding: 0 0 0 0 ;">

                </div>
            </div>

        </section>

        <div class="clearfix"></div>
    </div><!-- /.content-wrapper -->
    <!--内容区结束-->
    <!--页脚开始-->
    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b>  3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
    <!--页脚结束-->
</div>

<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/fastclick/fastclick.min.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<script src="assets/jQuery-File-Upload-9.12.3/js/vendor/jquery.ui.widget.js"></script>
<script src="assets/jQuery-File-Upload-9.12.3/js/jquery.iframe-transport.js"></script>
<script src="assets/jQuery-File-Upload-9.12.3/js/jquery.fileupload.js"></script>
<script src="assets/cxSelect-master/js/jquery.cxselect.min.js"></script>
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/DataTables-1.10.11/media/js/jquery.dataTables.min.js"></script>
<script src="assets/DataTables-1.10.11/media/js/dataTables.bootstrap.min.js"></script>
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script src="js/alert_check.js"></script>
<script>
    var server;
    var globalX,globalY;
    var totalPage = 1;
    var pageIndex = 1;
    var totalNum;
    var monitorMapArr;

    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        initMonitorTable();
        ReadTable();

        //excel上传
        $('#upload').click(function(){
            var formData = new FormData($("#fileForm")[0]);
            $.ajax({
                url:server + "/xk/xkMonitor/xlsImport",
                type:"POST",
                data:formData,
                async:false,
                cache:false,
                contentType:false,
                processData:false,
                success:function(Data_in){
                    var jsonObj = JSON.parse(Data_in);
                    console.log(jsonObj);
                    if(jsonObj.code == 0){
                        layer.alert('数据导入成功',{
                            closeBtn: 0
                        });
                        ReadTable();
                    }
                    else {
                        var errors = jsonObj.data.错误内容;
                        console.log(errors);
                        layer.alert(errors[0],{
                            closeBtn: 0
                        });
                    }
                },
                error:function(Data_in){
                    layer.alert('数据导入失败',{
                        closeBtn: 0
                    });
                }
            });
        })
        window.onload = checkAlert(server);
    });
    //excel文件地址显示
    $('input[id=map_file]').change(function() {
        var mp = $('#photoCover');
        mp.val($(this).val());
        console.log($(this).val());
    });
    //导出所有excel
    $('#exportAllXlsx').click(function () {
        window.open(server+'/xk/xkMonitor/xlsTemplateExport');
    });
    function ReadTable() {
        $.ajax({
            url:server+"/xk/xkMonitor/getAllNoPos" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                console.log(json);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    var monitorDataShow = [];
                    for(var i in json.data){
                        var datas = json.data;
                        var obj = {
                            id: datas[i].id,
                            name:datas[i].monitor_name,
                            device_name:datas[i].device_name,
                            location:datas[i].geo_1+'_'+datas[i].geo_2+'_'+datas[i].geo_3,
                            sensor_name:datas[i].sensor_name,
                            geo_3_id:datas[i].geo_3_id,
                        };
                        monitorDataShow.push(obj);
                    }
                    monitorTable.clear().draw();
                    monitorTable.rows.add(monitorDataShow).draw();
                }
//                layer.close(index);
            }
        });
    }
    function initMonitorTable() {
        monitorTable = $('#monitor_no_map_table').DataTable({
            paging: true,
            columns:[
                {data: "id"},
                {data: "name"},
                {data: "device_name"},
                {data: "location"},
                {data: "sensor_name"},
                {data: null,"width":"250px"}
            ],
            columnDefs:[{
                targets:5,
                render: function (data, type, row, meta) {
                    return '<div class="col-sm-12"><div class="col-sm-6" ><button type="button"class="btn btn-warning fa fa-edit" onclick=editRecord('+row.id+','+row.geo_3_id+')>设置坐标</button></div>' +
                            '<div class="col-sm-6"><button type="button" class="btn btn-danger fa fa-remove" onclick=delMonitor('+row.id+')>删除</button></div></div>';
                }
            },
                {   'orderable': false,
                    'targets': 5
                },],

            language:{
                "sProcessing":   "处理中...",
                "sLengthMenu":   "显示 _MENU_ 项结果",
                "sZeroRecords":  "没有匹配结果",
                "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix":  "",
                "sSearch":       "搜索:",
                "sUrl":          "",
                "sEmptyTable":     "表中数据为空。",
                "sLoadingRecords": "载入中...",
                "sInfoThousands":  ",",
                "oPaginate": {
                    "sFirst":    "首页",
                    "sPrevious": "上页",
                    "sNext":     "下页",
                    "sLast":     "末页"
                },
                "oAria": {
                    "sSortAscending":  ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    };
    function editRecord(id,geo_3_id) {
        console.log(id);
        console.log(geo_3_id);
        var posX = 0;
        var posY = 0;
        layer.open({
            type: 1,
            title:'设定监测点坐标',
            skin:'layui-layer-lan',
            area:['800px', '600px'],
            content:'<div class="tab-pane" id="tab_0" style="width:98%">'
            +'  <div class="row">'
            +'      <div class="col-sm-12">'
            +'          <div class="box box-warning">'
            +'              <div class="box-body" id="change_monitor_box_body">'
            +'                  <div class="row">'
            +'                      <div class="col-sm-4">'
            +'                          <div class="form-group">'
            +'                              <label>监测点X坐标</label>'
            +'                              <input id="monitor_change_pos_x_input"  class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2 ">'
            +'                          <div class="form-group">'
            +'                              <label>监测点Y坐标</label>'
            +'                              <input id="monitor_change_pos_y_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div id="monitor_change_map_div" >'
            +'                      </div>'
            +'                  </div>'
            +'              </div>'
            +'          </div>'
            +'      </div>'
            +'  </div>'
            +'</div>'
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                posX = $('#monitor_change_pos_x_input').val();
                posY = $('#monitor_change_pos_y_input').val();
                var formDatas = new FormData();
                formDatas.append("id",id);
                formDatas.append("x",posX);
                formDatas.append("y",posY);
                $.ajax({
                    type:"post",
                    contentType : false,
                    processData:false,
                    url: server + "/xk/xkMonitor/updatePos" ,
                    data:formDatas,
                    success:function () {
                        layer.alert('数据修改成功！',{
                            closeBtn: 0
                        });
                        ReadTable();
                    }
                });
            },
            btn2:function (index,layero) {
            },
            success: function(){
                $("#monitor_change_pos_x_input").val(posX);
                $("#monitor_change_pos_y_input").val(posY);
                $('#monitor_change_map_div').empty();
                var imgs = "";
                imgs = '<img id="show_map" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="'+server+'/xk/xkGeoLocation/mapDownload?id='+geo_3_id+'" onclick="mapOnClick2(event)" />';
                $('#monitor_change_map_div').append(imgs);
                var w = $('#monitor_change_map_div').width();
                var h = $('#monitor_change_map_div').height();
            }
        });
    }
    function delMonitor(id) {
        var index = layer.load(0, {shade: false});
        $.ajax({
            url:server +'/xk/xkMonitor/delete?id=' + id,
            success:function (data) {
                layer.alert('数据删除成功！',{
                    closeBtn: 0
                });
                ReadTable();
                layer.close(index);
            }
        });
    }
    function mapOnClick2(e){
        console.log("Test");
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#monitor_change_pos_x_input').val(x.toFixed(10));
        $('#monitor_change_pos_y_input').val(y.toFixed(10));
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#monitor_change_map_div .mapBall").remove();
        }
        posSetBall2(w,h,x,y)
    }
    function posSetBall2(w,h,x,y) {
        var curX = w * x;
        var curY = h * y;
        $('<span class="mapBall">').css({
            width: 20,
            height: 20,
            left: curX + $('#monitor_change_map_div ').position().left-10,
            top: curY + $('#monitor_change_map_div ').position().top-10
        }).appendTo($('#monitor_change_map_div '));
    }
</script>
</body>
</html>